package net.hzlj.platform.enterprise.utils.recorder;

import android.app.Dialog;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import net.hzlj.rl.zhangjiajie.R;

/**
 * @ClassName: AudioDialogManager
 * @Description: 录音弹出框
 * @Author: Jason.Zhang zhangyujn1989ok@gmail.com
 * @Date: 2016-1-11 15:23:35
 */
public class RecorderDialogManager {

    private Dialog mDialog;

    private ImageView imgIcon;
    private ImageView imgVoice;
    private TextView tvLable;

    private TextView mTimeTextView;//时间显示

    private Context mContext;

    public RecorderDialogManager(Context context) {
        this.mContext = context;
    }

    /**
     * 显示录音界面
     */
    public void showRecordingDialog() {
        mDialog = new Dialog(mContext, R.style.Theme_AudioRecorderDialog);
        View view = LayoutInflater.from(mContext).inflate(
                R.layout.widget_recorder_dialog, null);
        mDialog.setContentView(view);

        imgIcon = (ImageView) view.findViewById(R.id.talkImgIcon);
        imgVoice = (ImageView) view.findViewById(R.id.talkImgVoice);
        tvLable = (TextView) view.findViewById(R.id.talkTvLable);
        mTimeTextView = (TextView) view.findViewById(R.id.dialog_time);
        mDialog.show();
    }

    //设置时间
    public void setTime(String time){
        if (null != mDialog && mDialog.isShowing()) {
            mTimeTextView.setText(time);
        }
    }

    public void recording() {
        if (null != mDialog && mDialog.isShowing()) {
            imgIcon.setVisibility(View.VISIBLE);
            imgVoice.setVisibility(View.VISIBLE);
            tvLable.setVisibility(View.VISIBLE);

            imgIcon.setImageResource(R.drawable.ic_recorder);
            //"手指上滑，取消发送"
            tvLable.setText(mContext.getString(R.string.recorder_dialog_message_up));
        }
    }

    /**
     * 取消录音界面
     */
    public void showWantCancelDialog() {
        if (null != mDialog && mDialog.isShowing()) {
            imgIcon.setVisibility(View.VISIBLE);
            imgVoice.setVisibility(View.GONE);
            tvLable.setVisibility(View.VISIBLE);

            imgIcon.setImageResource(R.drawable.ic_recorder_dialog_cancel);
            tvLable.setText(mContext.getString(R.string.recorder_dialog_message_release));
        }
    }

    /**
     * 录音时间过短界面
     */
    public void showTooShortDialog() {
        if (null != mDialog && mDialog.isShowing()) {
            imgIcon.setVisibility(View.VISIBLE);
            imgVoice.setVisibility(View.GONE);
            tvLable.setVisibility(View.VISIBLE);

            imgIcon.setImageResource(R.drawable.ic_voice_short);
//            tvLable.setText("录音时间过短");
            tvLable.setText(mContext.getString(R.string.recorder_dialog_message_short));
        }
    }

    public void dismissDialog() {
        if (null != mDialog && mDialog.isShowing()) {
            mDialog.dismiss();
        }
    }

    /**
     * 更新voice图片
     *
     * @param level
     *            1~7
     */
    public void updateVoiceLevel(int level) {
        if (null != mDialog && mDialog.isShowing()) {
            // 获取资源ID
            int resId = mContext.getResources().getIdentifier("ic_voice_" + level,
                    "drawable", mContext.getPackageName());
            imgVoice.setImageResource(resId);
        }
    }
}
